﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using StateManager;

namespace Demo_WinForm
{
    public partial class Form1 : Form
    {
        SManager _SManager;
        public Form1()
        {
            InitializeComponent();
            _SManager = new SManager(Log);
            chkboxAuto.Checked = _SManager.Auto;
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            _SManager?.Dispose();
        }

        private void checkBox1Auto_CheckedChanged(object sender, EventArgs e)
        {
            _SManager.Auto = chkboxAuto.Checked;
        }

        void Log(string node, string text, bool mode)
        {
            if (richTextBox1.IsHandleCreated)
            {
                richTextBox1.BeginInvoke(new Action(() =>
                {
                    richTextBox1.AppendText($"{DateTime.Now}  {node}  {text}\r\n");
                }));
            }
        }

    }
}
